<template>
	<view class="wanl-signin-log">
		<view class="edgeInsetTop"> </view>
		<view class="header">
			<view class="text-center">
				<view class="text-sl" style="color: #39b54a;font-size: 52upx;">
					{{user.score}}
				</view>
				<!-- <view class="text-sl" style="color: red;font-size: 52upx;">
					{{user.lockscore}}
				</view>
				<view class="text-sl" style="color: black;;font-size: 52upx;">
					{{user.secondscore}}
				</view> -->
				<view class="cu-btn bg-orange radius-bock margin-top-bj cu-btn-left" @tap="onScoreRank">
					查看签到排行榜
				</view>
				<view class="cu-btn bg-orange radius-bock margin-top-bj cu-btn-right" @click="zhuangrang()" style="margin-right: 32rpx;">
					转赠
				</view>
				<view class="cu-btn bg-orange radius-bock margin-top-bj cu-btn-right" @click="tsatdhxfj()">
					兑换消费金
				</view>
				
			</view>
		</view>
		<view class="cu-list menu-avatar">
			<view class="cu-item" v-for="(item, index) in dataList" :key="item.id">
				<view class="content">
					<view class="text-sm flex">
						<view class="text-cut">
							{{item.memo}}
						</view> 
					</view>
					<view class="wanl-gray text-sm">{{ timestampToTime(item.createtime) }}</view>
				</view>
				<view class="action">
					<view class="wanl-text-yellow text-lg" v-if="item.score<0">{{item.score}}</view>
					<view class="text-lg text-orange" v-else>{{item.score}}</view>
				</view>
			</view>
		</view>
		<view class="marke" v-show="seePoups">
			<view class="withdraw">
				<icon @click="seePoups=false,showmobile=false" class="cancel" type="clear" size="24" color="#ccc"  ></icon>
				<view class="markeTitle">{{title}}</view>
				<input class="moneyBox" type="digit" cursor-spacing="50px" :placeholder="placeholder1"  :value="number" placeholder-class="tips"@blur="changenumber"/>
				<input class="moneyBox" type="digit" cursor-spacing="50px" :placeholder="placeholder"  :value="mobile" placeholder-class="tips"@blur="changemobile"  v-show="showmobile" />
				<view class="tishi">{{tishi}}</view>
				<button @click="tijiao">提交</button>
				
			</view>
		</view>
		<view class="edgeInsetBottom"></view> 
		<uni-load-more :status="status" :content-text="contentText" />
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			dataList: [],
			reload: false, //判断是否上拉
			total: 0, //数据量
			current_page: 1, //当前页码
			last_page: 1, //总页码
			status: 'more',
			contentText: {
				contentdown: ' ',
				contentrefresh: '加载中',
				contentnomore: ''
			},
			seePoups:false,
			title:'兑换成卡',
			placeholder:'请输入兑换数量',
			url:'',
			tishi:'',
			number:'',
			mobile:'',
			showmobile:false,
			placeholder1:''
		};
	},
	computed: {
		...mapState(['user'])
	},
	onLoad() {
		this.loadData();
	},
	onPullDownRefresh() {
		this.current_page = 1;
		this.reload = true;
		this.loadData();
	},
	onReachBottom() {
		//判断是否最后一页
		if (this.current_page >= this.last_page) {
			this.status = 'noMore';
		} else {
			this.reload = false;
			this.current_page = this.current_page + 1; //页码+1
			this.status = 'loading';
			this.loadData();
		}
	},
	methods: {
		changenumber(e){
			
			this.number=e.detail.value
			//console.log(e)
			
		},
		changemobile(e){
			
			this.mobile=e.detail.value
			//console.log(e)
			
		},
		tijiao(){
			console.log(this.number)
			if(this.number==''||this.number<0){
				uni.showToast({
					title:'请输入转赠数量',
					icon:'none'
				})
				return false
			}
			if(this.showmobile){
				if(this.mobile==''){
					uni.showToast({
						title:this.placeholder,
						icon:'none'
					})
					return false
				}
			}
			
			// console.log(this.data)
			
			this.$api.post({
				url: this.url,
				data:{
					number:this.number,
					mobile:this.mobile
				} ,
				success: res => {
					//uni.stopPullDownRefresh();
					this.seePoups=false;
						uni.showToast({
							title:res,
							icon:'none'
						})
						// this.loadData();
						this.loading = false;
						this.$wanlshop.to('/pages/page/success?type=yongjinzhuanfujin');
					
				}
			});
		},
		zhuangrang(){
			this.seePoups=true,
			this.showmobile=true,
			this.title='转赠',
			this.placeholder='请填写接收人手机号码',
			this.url='/wanlshop/user/givescore',
			this.placeholder1='请输入转赠数量'
			this.tishi=''
		},
		tsatdhxfj(){
			this.seePoups=true,
			this.showmobile=false,
			this.title='兑换消费金',
			this.placeholder1='请输入兑换数量',
			this.tishi='TAST可以两倍兑换消费金',
			this.url='/wanlshop/Shuzihushen/tsatdhxfj'
			
		},
		async loadData() {
			this.$api.post({
				url: '/wanlshop/user/scoreLog',
				data: {
					page: this.current_page
				},
				success: res => {
					uni.stopPullDownRefresh();
					this.dataList = this.reload ? res.data : this.dataList.concat(res.data);//数据 追加
					this.total = res.total; //数据量
					this.current_page = res.current_page; //当前页码
					this.last_page = res.last_page; //总页码
					this.status = res.total == 0 ? 'noMore' : 'more';
				}
			});
		},
		timestampToTime(timestamp) {
			var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
			var Y = date.getFullYear() + '-';
			var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
			var D = (date.getDate() < 10 ?'0'+date.getDate():date.getDate()) + ' ';
			var h = date.getHours() + ':';
			var m = date.getMinutes() + ':';
			var s = date.getSeconds();
			return Y+M+D+h+m+s;
		},
		onScoreRank(){
			this.$wanlshop.to('/pages/user/signin/rank');
		}
	}
};
</script>

<style>
	.cu-btn-left{
		margin-right: 30rpx;
	}
	.wanl-signin-log .header{
		display: flex;
		justify-content: center;
		align-items: center;
		height: 300rpx;
	}
	
	.wanl-signin-log .cu-list.menu-avatar>.cu-item .content{
		left: 25rpx;
	}
	.marke{
		width: 100%;
		height: 100%;
		position: fixed;
		top:0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 990;
		background: rgba(0,0,0,0.7);
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.tishi{
		padding-left: 30rpx;
		color: #888;
		
	}
	.withdraw{
		width: 80%;
		background: #fff;
		border-radius: 20rpx;
		position: relative;
	}
	.markeTitle{
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		font-size: 32rpx;
		color: #333;
		text-align: center;
		background: #f5f5f5;
		border-radius: 20rpx 20rpx 0 0;
	}
	.moneyBox{
		width: 90%;
		height: 100rpx;
		line-height: 100rpx;
		border-bottom: 2rpx solid red;
		margin: 20rpx 5%;
		text-align: center;
		font-size: 42rpx;
		font-weight: bold;
		color: red;
	}
	.tips{
		font-size: 30rpx;
		color: #bebebe;
		text-align: center;
		font-weight: normal;
	}
	.withdraw button{
		width: 90%;
		margin: 20rpx 5%;
		margin-top: 40rpx;
		font-size: 32rpx;
		height: 88rpx;
		line-height: 88rpx;
		border: none;
		background: #007AFF;
		color: #fff;
	}
	.withdraw button::after{
		border: none;
	}
	.cancel{
		position: absolute;
		top: -20rpx;
		right: -20rpx;
		background: #fff;
		border-radius: 50%;
		z-index: 999;
		
	}
	.wanl-signin-log .header{
		display: flex;
		justify-content: center;
		align-items: center;
		height: 300rpx;
	}
	
	.wanl-signin-log .cu-list.menu-avatar>.cu-item .content{
		left: 25rpx;
	}
	
</style>
